package cn.com.ly.service;

import cn.com.ly.dao.UserDAO;
import cn.com.ly.model.User;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component("userService")
public class UserService {

    private UserDAO userDAO;

    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public void add(String name) {
        userDAO.save(name);
    }

    public List<Long> getUserIdList() {
        return userDAO.getUserIdList();
    }

    public List<User> getUsers() {
        return userDAO.getUsers();
    }

    public List<User> getTop(int length) {
        String sql = "select * from test.user u where 1=1 order by u.username asc, u.password desc limit ? ";
        return this.userDAO.list(User.class, sql, length);
    }

    public List<Map<String, Object>> getUserList() {
        return userDAO.getUserList();
    }

    public UserDAO getUserDAO() {
        return userDAO;
    }

    @Resource(name = "userDAO")
    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }
}